# https://jasonkayzk.github.io/2020/12/06/Bash命令自动补全的原理/

import os
import sys


PINFRAC_ROOT = os.environ.get("PINFRAC_ROOT", "~/.pinfrac")
PINFRAC_USERDATA_LOG = os.environ.get("PINFRAC_USERDATA", PINFRAC_ROOT + "/_userdata") + "/log.txt"


_raw_print = print
print = None


def log(s):
    with open(PINFRAC_USERDATA_LOG, "a+") as fp:
        _raw_print(s, file=fp)


def reply(s):
    _raw_print(s)


def main():
    COMP_LINE = sys.argv[2:]
    COMP_CWORD = min(int(sys.argv[1]), len(COMP_LINE) - 1)
    log(f"{COMP_LINE}, {COMP_CWORD}")
    
    # reply("hello")


if __name__ == "__main__":
    main()
